
/*
 * Name: enumhost
 * Version: 0.2.0
 * Description: Enumerate the hosts associated with a hostname
 * Dependencies: bzbnet, bzbutil
 */

#include "balzebub.h"

using namespace bzbio;
using namespace bzbterm;

constexpr int VERSION_MAJOR = 0;
constexpr int VERSION_MINOR = 2;
constexpr int VERSION_PATCH = 0;

const char* PROGNAME = "enumhost";


void print_help_exit(int err = 0) {
	println("Usage: ", PROGNAME, " [ -h | --help ] | <filename>");
	println("Enumerate the hosts associated with the given hostname");
	println("-h | --help\tShow this help");
	exit(err);
}


void print_version_exit() {
	print(PROGNAME, " v");
	println(VERSION_MAJOR, ".", VERSION_MINOR, ".", VERSION_PATCH);
	println("This program is part of the Balzebub project.");
	exit(0);
}


int main(int argc, char const *argv[]) {

	if(argc < 2) {
		print_help_exit(1);
	}

	std::string arg(argv[1]);

	if(arg == "-v" || arg == "--version") {
		print_version_exit();
	}

	if(arg == "-h" || arg == "--help") {
		print_help_exit();
	}

	std::vector<std::string> addresses;

	try {
		addresses = bzbnet::get_host_list(arg);
	} catch(std::exception& e) {
		println("Unable to enumerate host list. ERROR:\n", e.what());
	}

	for(int i = 0; i < addresses.size(); ++i) {
		if(i % 2) {
			println(fg::white, addresses[i]);
		} else {
			println(fg::bright_white, addresses[i]);
		}
	}

	return 0;
}